﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WPFEdit.Document
{
	/// <summary>
	/// Encapsulates document data.
	/// </summary>
    public class Document
    {
        protected string m_fileName;

        protected string m_filePath;

        protected object m_documentData;

        public virtual object DocumentData
        {
            get { return m_documentData; }
            set
            {
                if (m_documentData != null && m_documentData is IEditable)
                {
                    ((IEditable)m_documentData).DirtyChanged -= DataDirtyChanged;
                }
                m_documentData = value;
                if (m_documentData != null && m_documentData is IEditable)
                {
                    ((IEditable)m_documentData).DirtyChanged += DataDirtyChanged;
                }
            }
        }

        void DataDirtyChanged(object sender, ValueChangedEventArgs<bool> e)
        {
            if (DataChanged != null && e.NewValue)
            {
                DataChanged(this, new EventArgs());
            }
        }

        public virtual string FilePath
        {
            get { return m_filePath; }
            set { m_filePath = value; }
        }

        public virtual string FileName
        {
            get { return m_fileName; }
            set { m_fileName = value; }
        }

		/// <summary>
		/// Occurs when the document Data is IEditable and the data changes.
		/// </summary>
        public event EventHandler DataChanged;
    }
}
